<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器</title>
</head>
<body>
    <p>
        整数1：
        <input type="text" id="zhengshu1">
    </p>
    <p>
        整数2：
        <input type="text" id="zhengshu2">
    </p>
    <p>
        <button onclick="sum('jia')">相加</button>
        <button onclick="sum('jian')">相减</button>
        <button onclick="sum('cheng')">相乘</button>
        <button onclick="sum('chu')">相除</button>
    </p>
    <p>
        结果：
        <input type="text" id="res">
    </p>

    <script>
        function sum(e){
            var text=document.querySelector("#zhengshu1").value;
            text=Number(text);
            var text2=document.querySelector("#zhengshu2").value;
            text2=Number(text2);
            var res=0;
            switch(e){
                case 'jia':
                res=text+text2;
                    break;
                case 'jian':
                    res=text-text2;
                    break;
                case 'cheng':
                    res=text*text2;
                    break;
                case 'chu':
                    res=text/text2;
                    break;
            }
            document.querySelector("#res").value=res;
        }
    </script>
</body>
</html>